

import java.lang.reflect.Method;
import java.io.IOException;




/*
Any task that can not be non in a pure-java system independent way should be done in this class.
*/
/**
This class provides methods for operations that cannot be done without knowing the operating system the program is running on.
*/
public class SystemSpecific {
	
	public static String getOS() {
		return System.getProperty("os.name");
	}
	
	/*
	This method is an adaption of the code found at http://www.centerkey.com/java/browser/
	The page says the code is free, but does not specify a license.
	*/
	/**
	*/
	public static void launchWebBrowser(String url) throws Exception {
		String osName = getOS();
		if (osName.startsWith("Mac OS")) {
			Class fileMgr = Class.forName("com.apple.eio.FileManager");
			Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] {String.class});
			openURL.invoke(null, new Object[] {url});
		} else if (osName.startsWith("Windows")) {
			Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
		} else { //assume Unix or Linux
			String[] browsers = {"firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" };
			String browser = null;
			for (String browsername: browsers) {
				if (Runtime.getRuntime().exec(new String[] {"which", browsername}).waitFor() == 0) {
					browser = browsername;
					break;
				}
			}
			if (browser == null) throw new Exception("Could not find web browser");
			else Runtime.getRuntime().exec(new String[] {browser, url});
		}
	}
	
}
